#include "stdafx.h"
#include "GraphicFactory.h"
#include "Graphic.h"
#include "DecorativeLine.h"
#include "Label.h"
#include "Station.h"
#include "Section.h"
#include "SSwitch.h"
#include "Signal.h"
#include "Clock.h"
#include "DecorativeLight.h"
#include "Button.h"


std::map<int, GraphicFactory::CreateCallBack> GraphicFactory::__CreateFucMap;


GraphicFactory::GraphicFactory(void)
{
}


GraphicFactory::~GraphicFactory(void)
{
}


void GraphicFactory::RegistGraphic()
{
	__CreateFucMap[Graphic::GRAPHIC_DECORATIVE_LINE] = DecorativeLine::CreateGraphic;
	__CreateFucMap[Graphic::GRAPHIC_STATIC_TEXT]     = Label::CreateGraphic;
	__CreateFucMap[Graphic::GRAPHIC_STATION]         = Station::CreateGraphic;
	__CreateFucMap[Graphic::GRAPHIC_SECTION]         = Section::CreateGraphic;

	__CreateFucMap[Graphic::GRAPHIC_SWITCH_LU_S] = SSwitch::CreateGraphic;
	__CreateFucMap[Graphic::GRAPHIC_SWITCH_LD_S] = SSwitch::CreateGraphic;
	__CreateFucMap[Graphic::GRAPHIC_SWITCH_RU_S] = SSwitch::CreateGraphic;
	__CreateFucMap[Graphic::GRAPHIC_SWITCH_RD_S] = SSwitch::CreateGraphic;

	__CreateFucMap[Graphic::GRAPHIC_SWITCH_LU_B] = SSwitch::CreateGraphic;
	__CreateFucMap[Graphic::GRAPHIC_SWITCH_LD_B] = SSwitch::CreateGraphic;
	__CreateFucMap[Graphic::GRPAHIC_SWITCH_RU_B] = SSwitch::CreateGraphic;
	__CreateFucMap[Graphic::GRPAHIC_SWITCH_RD_B] = SSwitch::CreateGraphic;

	__CreateFucMap[Graphic::GRPAHIC_SIGNAL_HD_UP] = Signal::CreateGraphic;
	__CreateFucMap[Graphic::GRAPHIC_SIGNAL_HS_UP] = Signal::CreateGraphic;
	__CreateFucMap[Graphic::GRAPHIC_SIGNAL_LD_UP] = Signal::CreateGraphic;
	__CreateFucMap[Graphic::GRAPHIC_SIGNAL_LS_UP] = Signal::CreateGraphic;

	__CreateFucMap[Graphic::GRAPHIC_SIGNAL_HD_DOWN] = Signal::CreateGraphic;
	__CreateFucMap[Graphic::GRAPHIC_SIGNAL_HS_DOWN] = Signal::CreateGraphic;
	__CreateFucMap[Graphic::GRAPHIC_SIGNAL_LD_DOWN] = Signal::CreateGraphic;
	__CreateFucMap[Graphic::GRAPHIC_SIGNAL_LS_DOWN] = Signal::CreateGraphic;

	__CreateFucMap[Graphic::GRAPHIC_TIME] = Clock::CreateGraphic;
	__CreateFucMap[Graphic::GRAPHIC_DECORATIVE_LIGHT] = DecorativeLight::CreateGraphic;

	__CreateFucMap[Graphic::Graphic_BUTTON] = Button::CreateGraphic;
}


Graphic* GraphicFactory::CreateGraphic(int type)
{
	auto it = __CreateFucMap.find(type);

	if (it != __CreateFucMap.end())
	{
		Graphic* pGraphic = (it->second)();
		pGraphic->_type = type;
		
		return pGraphic;
	}
	else
	{
		return NULL;
	}
}

